package com.yanqu.road.entity.wingroom;

import com.yanqu.road.entity.wingroom.config.WingRoomFurnitureConfig;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ：zfr
 * @date ：2022/1/19 15:09
 *  厢房家具
 */
public class WingRoomFurniture {
    //家具id
    private int furnitureId;
    //原点块坐标
    private RegionBlock originBlock;
    //朝向
    private int faceDirection;
    //当前厢房内的家具编号
    private int no;

    public int getFurnitureId() {
        return furnitureId;
    }

    public void setFurnitureId(int furnitureId) {
        this.furnitureId = furnitureId;
    }

    public RegionBlock getOriginBlock() {
        return originBlock;
    }

    public void setOriginBlock(RegionBlock originBlock) {
        this.originBlock = originBlock;
    }

    public int getFaceDirection() {
        return faceDirection;
    }

    public void setFaceDirection(int faceDirection) {
        this.faceDirection = faceDirection;
    }

    public int getNo() {
        return no;
    }

    public void setNo(int no) {
        this.no = no;
    }

    public boolean checkInBounds(List<RegionBlock> regionBlockList, List<RegionBlock> blockList) {
        for (RegionBlock block : blockList) {
            if (!regionBlockList.contains(block)) {
                return false;
            }
        }
        return true;
    }

    public List<RegionBlock> getBlockList(WingRoomFurnitureConfig config) {
        List<RegionBlock> regionBlockList = new ArrayList<>();
        int xLen = Math.max(config.getxLen(), config.getyLen());
        int yLen = Math.min(config.getxLen(), config.getyLen());

        if (faceDirection != eWingRoomDirectionEnum.FRONT.getDirection()) {
            xLen = Math.min(config.getxLen(), config.getyLen());
            yLen = Math.max(config.getxLen(), config.getyLen());
        }
        int originX = originBlock.getX();
        int originY = originBlock.getY();

        for (int i = 0; i < xLen; i++) {
            for (int j = 0; j < yLen; j++) {
                regionBlockList.add(new RegionBlock(originX + xLen - i - 1, originY + yLen - j - 1));
            }
        }
        return regionBlockList;
    }

    public boolean isFloor() {
        return false;
    }

    public WingRoomFurniture clone() {
        WingRoomFurniture furniture = new WingRoomFurniture();
        furniture.setFurnitureId(this.furnitureId);
        furniture.setNo(this.no);
        furniture.setFaceDirection(this.faceDirection);
        furniture.setOriginBlock(new RegionBlock(this.originBlock.getX(), this.originBlock.getY()));
        return furniture;
    }
}
